Imports System.Net
Imports System.Net.Sockets
Public Class BaseConnection
    Implements Connection
    Private _socket As Net.Sockets.Socket
    Private _host As IPAddress
    Private _port As String
    Public Sub Send(ByVal package As Package) Implements Connection.Send
        _socket.SendTo(package.rawData, SocketFlags.None, New IPEndPoint(_host, _port))
        'Me.SendTo(package.rawData, SocketFlags.None
    End Sub
    Public Sub Send(ByVal message As String) Implements Connection.Send
        _socket.SendTo(Text.Encoding.ASCII.GetBytes(message), SocketFlags.None, New IPEndPoint(_host, _port))
    End Sub

    Public Sub New()
        _socket = New Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork, Net.Sockets.SocketType.Stream, Net.Sockets.ProtocolType.IP)
    End Sub

    Public Property Host() As IPAddress Implements Connection.Host
        Get
            Return _host
        End Get
        Set(ByVal value As IPAddress)
            _host = value
        End Set
    End Property

    Public Property Port() As Integer Implements Connection.Port
        Get
            Return _port
        End Get
        Set(ByVal value As Integer)
            _port = value
        End Set
    End Property

    Public Overloads Sub close() Implements Connection.close
        _socket.Close()
    End Sub

    Public Sub Connect() Implements Connection.Connect
        _socket.Connect(New IPEndPoint(_host, _port))
    End Sub


    Public Event dataReceived(ByVal data() As Byte) Implements Connection.dataReceived

    Public Event dataSent(ByVal data As String) Implements Connection.dataSent
End Class
